package com.jz.digital.splash

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.content.Context
import android.content.Intent
import com.jz.digital.R
import com.jz.digital.base.BaseActivity
import com.jz.digital.base.BasePresenter
import com.jz.digital.login.LoginActivity
import com.jz.digital.main.MainActivity
import com.jz.digital.utils.SPHelper
import kotlinx.android.synthetic.main.activity_splash.layout_parent

/**
 * @author WangYong
 * @date 2024/11/18 17:45
 * @description:
 */
class SplashActivity : BaseActivity<BasePresenter<*>>() {
    /**
     * 动画时长
     */
    private val ANIM_DURATION = 2000L
    override fun getLayoutResId(): Int {
        return R.layout.activity_splash
    }

    override fun initViews() {
        super.initViews()
    }

    override fun initData() {
        super.initData()
        initAnimation()
    }

    /**
     * 初始化动画
     */
    private fun initAnimation() {
        layout_parent.alpha = 0.6f
        layout_parent.animate()
            .alpha(1f)
            .setDuration(ANIM_DURATION)
            .setListener(object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator) {
                    super.onAnimationEnd(animation)
                    // 动画结束时的操作
                    if (SPHelper.isLogin()) {
                        startActivity(Intent(this@SplashActivity, MainActivity::class.java))
                    } else {
                        LoginActivity.startActivity(this@SplashActivity)
                    }
//                    ZhiXiangRuKuCommitActivity.startActivity(this@SplashActivity)
                    finishAfterTransition()
                }
            })
    }

    companion object {
        @JvmStatic
        fun startActivity(context: Context) {
            context.startActivity(Intent(context, SplashActivity::class.java))
        }
    }
}